package com.jindi.jacococli.biz.business.task;

import com.jindi.jacococli.biz.business.model.ReportServiceProgress;
import com.jindi.jacococli.biz.business.model.ServiceProjectList;

import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 记录导出记录标识
 */
public class ReportTaskManager {

    private static final ConcurrentHashMap<String, ReportServiceProgress> REPORT_MANAGER = new ConcurrentHashMap<>();

    public static void add(ServiceProjectList task) {
        ReportServiceProgress progress = new ReportServiceProgress();
        progress.setUuid(task.getUuid());
        progress.setDescription("Submit Task Queue 【等待执行】");
        progress.setTotal(task.getServices().size());
        REPORT_MANAGER.put(task.getUuid(), progress);

    }

    public static ReportServiceProgress get(String uuid) {
        return REPORT_MANAGER.get(uuid);
    }

    public static void setDescribe(String uuid, String describe) {
        ReportServiceProgress progress = get(uuid);
        if (Objects.isNull(progress)) {
            return;
        }
        progress.setDescription(describe);
    }

    public static void addOver(String uuid) {
        ReportServiceProgress progress = get(uuid);
        if (Objects.isNull(progress)) {
            return;
        }
        progress.addOver();
    }

    public static void remove(String uuid) {
        REPORT_MANAGER.remove(uuid);
    }

}
